﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;

namespace opentk_first_project
{
    class Renderer
    {
        public Renderer()
        {
            GL.Enable(EnableCap.Blend);
            GL.BlendFuncSeparate(BlendingFactorSrc.ConstantColor, BlendingFactorDest.ConstantColor,
                BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.BlendFuncSeparate(
        }
        public void DrawImmediateModeVertex(Vector3d position, Color4 color, Vector2 uvs)
        {
            GL.Color4(color.R, color.B, color.G, color.A);
            GL.TexCoord2(uvs.X, uvs.Y);
            GL.Vertex3(position.X, position.Y, position.Z);
        }
        public void DrawSprite(Sprite sprite)
        {
            GL.Enable(EnableCap.Texture2D);
            GL.Begin(BeginMode.Triangles);
            {
                for (int i = 0; i < Sprite.VertexAmount; i++)
                {                    
                    GL.BindTexture(TextureTarget.Texture2D, sprite.Texture.Id);
                    DrawImmediateModeVertex(
                        sprite.VertexPositions[i],
                        sprite.VertexColors[i],
                        sprite.VertexUVs[i]);
                }
            }        
            try
            {

                GL.End();
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            GL.Disable(EnableCap.Texture2D);
        }
    }

    
}
